#include "telephone.h"

enum data
{
    INSERT = 1,
    DELETE,
    SEARCH,
    UPDATE,
    SHOW,
    EXIT
};

int main()
{
    DArray *a = InitDArray();
    int choice = 0;
    
    while (1) 
    {
        printf("\n1、插入新用户\n");
        printf("2、删除用户\n");
        printf("3、查看用户\n");
        printf("4、修改用户\n");
        printf("5、显示所有用户\n");
        printf("6、退出\n");
        printf("请输入你的选择：");
        if((scanf("%d", &choice)) != 1)
        {
            while (getchar() != '\n');
            printf("操作无效，请重新输入！\n");
            continue;
        }
        
        switch (choice) 
        {
            case 1:
                InsertTelephoneBook(a);
                break;
            case 2:
                DeleteTelephoneBook(a);
                break;
            case 3:
                SearchByInfo(a);
                break;
            case 4:
                UpdateTelephoneBook(a);
                break;
            case 5:
                ShowAll(a);
                break;
            case 6:
                ClearDArray(a, ClearTBook);
                return 0;
            default:
                printf("无效的选项，请重新输入。\n");
        }
    }
    ClearDArray(a, ClearTBook);
    return 0;
}